package com.yanqu.road.entity.activity.daomu.skillstrategy.active.impl;

import com.yanqu.road.entity.activity.daomu.DaoMuDamageBuff;
import com.yanqu.road.entity.activity.daomu.enums.DaoMuDamageBuffTypeEnum;
import com.yanqu.road.entity.activity.daomu.param.DaoMuCountSkillHurtReq;
import com.yanqu.road.entity.activity.daomu.enums.DaoMuAttributeEnum;
import com.yanqu.road.entity.activity.daomu.enums.DaoMuSkillHarmTypeEnum;
import com.yanqu.road.entity.activity.daomu.skillstrategy.active.ISkillActiveStrategy;
import com.yanqu.road.entity.activity.daomu.util.DaoMuSkillUtil;

import java.math.BigDecimal;
import java.util.Objects;

/**
 * 朱砂瓶
 */
public class SkillCinnabarStrategy implements ISkillActiveStrategy {

    /**
     * 计算技能伤害
     * @param req
     * @return
     */
    @Override
    public long countSkillHurt(DaoMuCountSkillHurtReq req) {
        //判断是主伤害，还是灼烧伤害
        long mySkillAttRate;//技能伤害千分比
        String[] skillParamArr = req.getDaoMuSkillConfig().getSkillPara().split("\\|");
        if (req.getSkillHarmType() == DaoMuSkillHarmTypeEnum.ATT_TYPE_1.getType()) {
            //灼烧伤害
            String skillParamAoe = skillParamArr[12];
            if (!Objects.equals(skillParamAoe, "0")) {
                return 0;
            }
            String[] skillParamAoeArr = skillParamAoe.split(";");
            mySkillAttRate = Long.parseLong(skillParamAoeArr[1]);
        } else {
            //爆炸伤害
            String skillParamAoe = skillParamArr[6];//范围伤害
            String[] skillParamAoeArr = skillParamAoe.split(";");
            mySkillAttRate = Long.parseLong(skillParamAoeArr[0]);
        }
        //攻击方攻击力
        BigDecimal myAttValue = req.getAttributeMap().get(DaoMuAttributeEnum.ATTRIBUTE_ATT.getType()).getValue();
        //攻击方攻击伤害加成千分比
        BigDecimal myHarmAddRate = req.getAttributeMap().get(DaoMuAttributeEnum.ATTRIBUTE_HARM_ADD_RATE.getType()).getValue();
        //攻击方暴击倍数千分表
        BigDecimal myCriticalValue = req.getAttributeMap().get(DaoMuAttributeEnum.ATTRIBUTE_CRITICAL_ATT.getType()).getValue();
        //对方防御力
        BigDecimal targetDefendValue = req.getTargetAttributeMap().get(DaoMuAttributeEnum.ATTRIBUTE_DEFEND.getType()).getValue();
        //对方伤害减免千分比
        BigDecimal targetNotHarmRate = req.getTargetAttributeMap().get(DaoMuAttributeEnum.ATTRIBUTE_NOT_HARM.getType()).getValue();
        //是否暴击
        boolean criticalFlag = req.isCriticalFlag();
        //破甲千分比
        long reDefendRate = 0;
        DaoMuDamageBuff reDefendDamageBuff = req.getDamageBuffMap().get(DaoMuDamageBuffTypeEnum.DAMAGE_BUFF_TYPE_RE_DEFEND.getType());
        if (reDefendDamageBuff != null) {
            reDefendRate = reDefendDamageBuff.getBuffValue();
        }
        //计算最终伤害
        return DaoMuSkillUtil.countSkillHurt(mySkillAttRate, myAttValue, myHarmAddRate, reDefendRate, myCriticalValue, criticalFlag, targetDefendValue, targetNotHarmRate);
    }
}
